<template>
  <div id="container">

    <div class="statistic-container">
      <div class="statistic-top">
        <div class="itemBox" v-for="(item, index) in statisticTopList" :key="index">
          <div class="img" v-if="item.imgSrc"><img :src="item.imgSrc" width="100%" height="100%" /></div>
          <div style="display: flex;width: 100%;">
            <div class="content">
              <div class="title">{{ item.title || '- -' }}</div>
              <div class="num">{{ item.value || '- -' }}</div>
            </div>
            <div style="font-size: 16px;display: flex;align-items: flex-end;">{{ item.unit }}</div>
          </div>
        </div>
      </div>

    </div>

  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive } from "vue";
import { allBaseInfoCount } from "@/common/api";
import { getAssetsFile } from '@/utils/getAssetsFile';

let goodsSum = reactive({})
let goodsSum3 = reactive({})
let amountSum = reactive({})
let amountSum3 = reactive({})

let statisticTopList = reactive([
  {
    value: "",
    title: "年度单量(单)",
  },
  {
    value: "",
    title: "年度吨位(吨)",
  },
  {
    value: "",
    title: "月度单量",
  },
  {
    value: "",
    title: "月度吨位",
  },
  {
    value: "",
    title: "今日单量",
  },
  {
    value: "",
    title: "今日吨位",
  },
])

let numberMoneyFormat = function (value) {
  if (typeof value === "string") { value = +(value); }
  let i
  let k = 10000
  let param = { value: 0, unit: '元' }
  let sizes = ['元', '万元', '亿', '万亿']
  if (value < k) { param.value = value.toFixed(2); param.unit = '元' }
  else { i = Math.floor(Math.log(value) / Math.log(k)); param.value = ((value / Math.pow(k, i))).toFixed(2); param.unit = sizes[i]; }
  return param;
}


onMounted(() => {
  allBaseInfoCount().then(res => {

    goodsSum = numberMoneyFormat(res.data.goodsSum);
    goodsSum3 = numberMoneyFormat(res.data.goodsSum3);
    amountSum = numberMoneyFormat(res.data.amountSum);
    amountSum3 = numberMoneyFormat(res.data.amountSum3);

    for (let i = 0; i < statisticTopList.length; i++) {
      statisticTopList[5].value = res.data.userCount;
      statisticTopList[4].value = res.data.waybillCount;
      statisticTopList[3].value = res.data.userCount;
      statisticTopList[2].value = res.data.waybillCount;
      statisticTopList[1].value = res.data.carInfoCountAdmin;
      statisticTopList[0].value = res.data.appUserCountAdmin + 2800;
    }

  })
})




</script>

<style scoped lang="scss">
#container {
  height: 100%;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;

  .statistic-container {
    height: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;

    .statistic-top {
      width: 100%;
      height: 100%;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;

      .itemBox {
        width: 40%;
        display: flex;
        align-items: center;
        margin: 0 10px;

        .img {
          width: 80px;
          height: 60px;

        }

        .content {
          flex: 1;
          height: 100%;
          display: flex;
          flex-direction: column;

          .title {
            font-size: 16px;
          }

          .num {
            color: #A3BEF1;
            font-size: 16px;
          }

          .amount {
            color: #a3bef1;
            font-size: 12px;
          }
        }
      }
    }

    .statistic-bottom {
      width: 90%;
      height: 45%;
      margin: 0 auto;
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: space-around;

    }
  }
}

.goodsSum3 {
  width: 90%;
  display: flex;
  margin: 0 auto;
  font-size: 16px;
  height: 46px;
  text-align: center;
  align-items: flex-end;

  img {
    height: 100%;
  }

  div {
    width: 50%;
    display: flex;
    flex-direction: column;
  }

  span {
    flex: 1;
    height: 100%;
  }
}

.goodsSum {
  width: 90%;
  display: flex;
  margin: 0 auto;
  height: 46px;
  font-size: 16px;
  text-align: center;
  align-items: flex-end;

  img {
    height: 100%;
  }

  div {
    width: 50%;
    display: flex;
    flex-direction: column;
  }

  span {
    flex: 1;
    height: 100%;
  }
}
</style>